package cn.kevenpotter.leetcode.easy.e28;

public class StrStr {

    public static void main(String[] args) {
        System.out.println(strStr("hello", "ll"));
    }

    public static int strStr(String haystack, String needle) {
        if (null == needle || "".equals(needle)) return 0;
        int haystackLength = haystack.length(), needleLength = needle.length();
        for (int start = 0; start < haystackLength; start++) {
            int largestPosition = start + needleLength;
            if ((largestPosition <= haystackLength) && haystack.substring(start, largestPosition).equals(needle)) return start;
        }
        return -1;
    }
}
